home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / gfx / 3d / Skulpt_src.lha / sKulpt-src / Ami-ResLoad.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-01  |  20.2 KB  |  718 lines

  1. #define STRICT
  2.  
  3. // Includes standard Windows
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <memory.h>
  10. #include <stdio.h>
  11.  
  12. // Includes D3D
  13. #define  D3D_OVERLOADS
  14. #include <ddraw.h>
  15. #include <d3d.h>
  16. #include <d3dx.h>
  17.  
  18. // Includes utilitaires D3D
  19. #include "d3dmath.h"
  20. #include "d3dutil.h"
  21. #include "D3DEnum.h"
  22.  
  23. // Ids Resources
  24. //#include "resource.h"
  25.  
  26. // Constantes
  27. #include "const.h"
  28.  
  29. // Types
  30. #include "types.h"
  31.  
  32. // Variables globales projet
  33. #include "vars.h"
  34.  
  35. // Prototypes fonctions autres modules
  36. #include "proto.h"
  37.  
  38. // Macros
  39. #include "macros.h"
  40.  
  41. // Macros locales
  42. static const XDC_IS_ORDINAL = 0;
  43. static const XDC_IS_NAME    = 1;
  44. #define XDC_C_FACTOR 17/10
  45.  
  46. // Types locaux
  47. typedef union 
  48. {
  49.     UWORD    wOrd;
  50.     char    szName[80];
  51. } OrdinalOrName;
  52.  
  53. typedef struct
  54. {
  55.     DWORD dwDataSize;
  56.     DWORD dwHeaderSize;
  57.     DWORD dwDataVersion;
  58.     UWORD wMemoryFlags;
  59.     UWORD wLanguageId;
  60.     DWORD dwVersion;  
  61.     DWORD dwCharacteristics; 
  62.     LPCTSTR lpType;
  63.     LPCTSTR lpName;
  64.     UINT  uResTypeTag;
  65.     OrdinalOrName ResType;
  66.     UINT  uResNameTag;
  67.     OrdinalOrName ResName;
  68.     void    *Data;
  69. }  ResEntry;
  70.  
  71. #define XDC_MAXGADSTR   64
  72. #define XDC_MAXWINSTR   128
  73.  
  74. // Globales (ce module est un peu sac à globales, pour arriver à partager le Wait() avec les autres fenêtres tout en
  75. // conservant une compatibilité 100% API Windows)
  76. static unsigned char *amsResBasePtr;        // Base des ressources
  77. static unsigned long amsResSize;            // Tailles des ressources
  78. static int iDlgResult;                      // Valeur retournée par le dialogproc dans EndDialog(...)
  79. static DLGPROC bDlgFunc;                    // DlgProc
  80. static char cTitre[XDC_MAXWINSTR];          // Titre dialog
  81. static Gadget *hGadgetList = NULL;
  82. static char cGadStr[256][XDC_MAXGADSTR];
  83. static unsigned char iLabel;
  84.  
  85. static HWND CreateWindow(ULONG x, ULONG y, ULONG largeur, ULONG hauteur, char *titre)
  86. {
  87.     Gadget *gad = CreateContext(&hGadgetList);
  88.  
  89.     strncpy(cTitre, titre, sizeof(cTitre) -1);
  90.  
  91.     HWND hDlg = OpenWindowTags(NULL,
  92.                 WA_Left,        x,
  93.                 WA_Top,         y,
  94.                 WA_Width,       largeur * XDC_C_FACTOR + hInst -> WBorLeft + hInst -> WBorRight,
  95.                 WA_Height,      hauteur * XDC_C_FACTOR + hInst -> WBorTop + hInst -> BarHeight + hInst -> WBorBottom,
  96.                 WA_Title,       cTitre,
  97.                 WA_Gadgets,     gad,
  98.                 WA_CustomScreen,(ULONG) hInst,
  99.                 WA_DepthGadget, TRUE,
  100.                 WA_DragBar,     TRUE,
  101.                 WA_Activate,    TRUE,
  102.                 WA_IDCMP,       IDCMP_VANILLAKEY | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MOUSEMOVE);
  103.  
  104.      iLabel = 0;
  105.  
  106.      return hDlg;
  107. }
  108.  
  109. static void AddGad(HWND hWnd, ULONG lType, ULONG lLeft, ULONG lTop, ULONG lWidth, ULONG lHeight, char *sGadgetText, UWORD wId, DWORD dwStyle)
  110. {
  111.     Gadget *hPrevGad = hWnd -> FirstGadget, *hGad;
  112.     static NewGadget newGad;
  113.     char *sText = &(cGadStr[iLabel][0]);
  114.  
  115.     // Si on a un label, le recopier dans une zone allouée pour le gadget
  116.     strcpy(sText, sGadgetText);
  117.  
  118.     // Créer le newgadget
  119.     newGad.ng_LeftEdge     = lLeft * XDC_C_FACTOR + hWnd -> BorderLeft;
  120.     newGad.ng_TopEdge      = lTop  * XDC_C_FACTOR + hWnd -> BorderTop; //WScreen -> BarHeight;
  121.     newGad.ng_Height       = (lType == TEXT_KIND) ? 16 : lHeight * XDC_C_FACTOR;
  122.     newGad.ng_Width        = (lType == CHECKBOX_KIND) ? newGad.ng_Height : lWidth * XDC_C_FACTOR;
  123.     newGad.ng_GadgetText   = sText;
  124.     newGad.ng_UserData     = (APTR) lType;
  125.     newGad.ng_TextAttr     = NULL;
  126.     newGad.ng_GadgetID     = wId;
  127.     newGad.ng_Flags        = (lType == CHECKBOX_KIND) ? PLACETEXT_RIGHT : PLACETEXT_IN;
  128.     newGad.ng_VisualInfo   = hVi;
  129.  
  130.     // L'insérer en dernier dans la fenêtre
  131.     while (hPrevGad -> NextGadget) hPrevGad = hPrevGad -> NextGadget;
  132.     if (lType == SLIDER_KIND && (dwStyle & 1)) // Si on a un slider vertical
  133.         hGad = CreateGadget(lType, hPrevGad, &newGad, PGA_FREEDOM, LORIENT_VERT, TAG_DONE);
  134.     else
  135.         hGad = CreateGadget(lType, hPrevGad, &newGad, TAG_DONE);
  136.  
  137.     if (hGad) iLabel++;
  138. }
  139.  
  140. BOOL DLGInit(char *sResFileName)
  141. {
  142.     BPTR hFileLock = Lock(sResFileName, SHARED_LOCK);
  143.  
  144.     if (!hFileLock) return FALSE;
  145.  
  146.     FileInfoBlock sFib;
  147.     BOOL bOk = FALSE;
  148.  
  149.     if (Examine(hFileLock,&sFib) && sFib.fib_DirEntryType < 0 && sFib.fib_Size > 0)
  150.     {
  151.         amsResSize = sFib.fib_Size;
  152.         amsResBasePtr = (unsigned char *) AllocVec(amsResSize,MEMF_ANY|MEMF_PUBLIC);
  153.         if (amsResBasePtr != NULL)
  154.         {
  155.             BPTR hFileHandle = Open(sResFileName,MODE_OLDFILE);
  156.  
  157.             if (hFileHandle)
  158.             {
  159.                 if (Read(hFileHandle,amsResBasePtr, amsResSize) == amsResSize)
  160.                     bOk = TRUE;
  161.  
  162.                 Close(hFileHandle);
  163.             }
  164.         }
  165.     }
  166.     UnLock(hFileLock);
  167.  
  168.     if (!bOk)
  169.     {
  170.         FreeVec(amsResBasePtr);
  171.         amsResBasePtr = NULL;
  172.         amsResSize = 0;
  173.         return FALSE;
  174.     }
  175.     return TRUE;
  176. }
  177.  
  178. void DLGClose(void)
  179. {
  180.     if (amsResBasePtr)
  181.     {
  182.         FreeVec(amsResBasePtr);
  183.         amsResBasePtr = NULL;
  184.     }
  185. }
  186.  
  187. static UWORD IntelWord(UWORD *addr)
  188. {
  189.     unsigned char B1, B2;
  190.  
  191.     B1 = *((unsigned char *) addr);
  192.     B2 = *(((unsigned char *) addr) + 1);
  193.     return (UWORD) B1 | ((UWORD) B2 << 8);
  194. }
  195.  
  196. static DWORD IntelLong(DWORD *addr)
  197. {
  198.     UWORD W1, W2;
  199.  
  200.     W1 = IntelWord((UWORD*) addr);
  201.     W2 = IntelWord(((UWORD*) addr) + 1);
  202.     return (ULONG) W1 | ((ULONG) W2 << 16);
  203. }
  204.  
  205. // Lit un objet encodé sous la forme name ou ordinal
  206. static int ReadNameOrOrdinal(unsigned char **pos, UWORD *wOrdinal, char *Name)
  207. {
  208.     unsigned char *carPtr;
  209.  
  210.     carPtr = *pos;
  211.  
  212.     if ((carPtr[0] == 0xFF) && (carPtr[1] == 0xFF))
  213.     {
  214.         // C'est un ordinal (UWORD suivant 0xFFFF)
  215.         *wOrdinal = IntelWord((UWORD*)&carPtr[2]);
  216.         *pos = *pos + 4;
  217.         return XDC_IS_ORDINAL;
  218.     }
  219.     else
  220.     {
  221.         while(*Name++ = *carPtr) carPtr += 2;
  222.         
  223.         *pos = carPtr + 2;
  224.         return XDC_IS_NAME;
  225.     }
  226. }
  227.  
  228. static unsigned char *ReadResEntry(unsigned char *pos, ResEntry *res)
  229. {
  230.     DWORD dwTaille;
  231.  
  232.     dwTaille = res -> dwDataSize = IntelLong(((DWORD*) pos)++ );
  233.     res -> dwHeaderSize = IntelLong(((DWORD*) pos)++ );
  234.     res -> uResTypeTag = ReadNameOrOrdinal(&pos, &(res -> ResType.wOrd), res -> ResType.szName);
  235.     res -> uResNameTag = ReadNameOrOrdinal(&pos, &(res -> ResName.wOrd), res -> ResName.szName);
  236.  
  237.     if (res -> uResTypeTag == 0)
  238.         res -> lpType = MAKEINTRESOURCE(res -> ResType.wOrd);
  239.     else
  240.         res -> lpType = (LPCTSTR)res -> ResType.szName;
  241.  
  242.     if (res -> uResNameTag == 0)
  243.         res -> lpName = MAKEINTRESOURCE(res -> ResName.wOrd);
  244.     else
  245.         res -> lpName  = (LPCTSTR)res -> ResName.szName;
  246.  
  247.     res -> dwDataVersion     = IntelLong(((DWORD*) pos)++);
  248.     res -> wMemoryFlags      = IntelWord(((UWORD*) pos)++);
  249.     res -> wLanguageId       = IntelWord(((UWORD*) pos)++);
  250.     res -> dwVersion         = IntelLong(((DWORD*) pos)++);
  251.     res -> dwCharacteristics = IntelLong(((DWORD*) pos)++);
  252.     res -> Data = pos;
  253.  
  254.     // Skip DataSize multiple de 4
  255.     if ((dwTaille & 0x3) != 0) dwTaille = (dwTaille & 0xFFFFFFFC) + 4;
  256.     return pos + dwTaille;
  257. }
  258.  
  259. // Compare deux LPCTSTR
  260. static int CheckLPCT(LPCTSTR lp1, LPCTSTR lp2)
  261. {
  262.     // On ne peut comparer que des types compatibles
  263.     if ((((long)lp1 & 0xFFFF0000) == 0) && (((long)lp2 & 0xFFFF0000) == 0))
  264.     {
  265.         // Ordinal
  266.         if ((long)lp1 == (long)lp2) return -1;
  267.         return 0;
  268.     }
  269.  
  270.     if ((((long)lp1 & 0xFFFF0000) != 0) && (((long)lp2 & 0xFFFF0000) != 0))
  271.     {
  272.         if (strcmp((char*)lp1, (char*)lp2) == 0) return -1;
  273.         return 0;
  274.     }
  275.  
  276.     return 0;
  277. }
  278.  
  279. // Récupère une WSTRING dans la ressource et en fait une string non unicode
  280. static unsigned char *myGetString(unsigned char *ucChar, char *szString)
  281. {
  282.     while(*szString++ = *ucChar ) ucChar += 2;
  283.  
  284.     ucChar += 2;
  285.  
  286.     return ucChar;
  287. }
  288.  
  289. // Appelé en boucle pour chaque item de la structure de la dialog pour ajouter
  290. // l'item à la fenêtre
  291. static unsigned char *myLoadDialogItem(HWND hWnd, unsigned char *ucData)
  292. {
  293.     DWORD    dwHelpID;
  294.     DWORD    dwStyle;
  295.     DWORD    dwExtendedStyle; 
  296.     UWORD     wID;
  297.     short    x, y, cx, cy; 
  298.     UWORD     wExtraBytes;
  299.     UWORD     wTagNom, wTagClasse;
  300.     OrdinalOrName leNom;
  301.     OrdinalOrName laClasse;
  302.  
  303.     // DialogItem est alignée sur un DWORD
  304.     if ((long)ucData & 3)
  305.         ucData = (unsigned char*) (((long)ucData & 0xFFFFFFFC) + 4);
  306.  
  307.     // Lecture des champs
  308.     dwHelpID        = IntelLong(((DWORD*) ucData)++);
  309.     dwExtendedStyle = IntelLong(((DWORD*) ucData)++);
  310.     dwStyle            = IntelLong(((DWORD*) ucData)++);
  311.     x                = IntelWord(((UWORD*)  ucData)++);
  312.     y                = IntelWord(((UWORD*)  ucData)++);
  313.     cx                = IntelWord(((UWORD*)  ucData)++);
  314.     cy                = IntelWord(((UWORD*)  ucData)++);
  315.     wID             = IntelWord(((UWORD*)  ucData)++);
  316.     ucData+=2;
  317.  
  318.     wTagClasse = ReadNameOrOrdinal(&ucData, &(laClasse.wOrd), laClasse.szName );
  319.     wTagNom = ReadNameOrOrdinal(&ucData, &(leNom.wOrd), leNom.szName );
  320.     wExtraBytes = IntelWord(((UWORD*)ucData)++);
  321.  
  322.     ULONG aType = ~0;
  323.     switch(laClasse.wOrd)
  324.     {
  325.         case 0x0080:
  326.             switch(dwStyle & 0xF)
  327.             {
  328.                 case BS_RADIOBUTTON:
  329.                 case BS_AUTORADIOBUTTON:
  330.                 case BS_CHECKBOX:
  331.                 case BS_AUTOCHECKBOX:
  332.                      aType = CHECKBOX_KIND;  break;
  333.                 case BS_GROUPBOX:
  334.                      aType = TEXT_KIND;      break;
  335.                 default:
  336.                      aType = BUTTON_KIND;    break;
  337.             }
  338.             break;
  339.         case 0x0081: aType = STRING_KIND;   break;
  340.         case 0x0082: aType = TEXT_KIND;     break;
  341.         case 0x0083: aType = LISTVIEW_KIND; break;
  342.         case 0x0084: aType = SLIDER_KIND;   break;
  343.         case 0x0085: aType = CYCLE_KIND;    break;
  344.     }
  345.     if (aType != ~0)
  346.         AddGad(hWnd, aType, x, y, cx, cy, leNom.szName, wID, dwStyle);
  347.  
  348.     return ucData + wExtraBytes;
  349. }
  350.  
  351. // Charge le dialogbox à partir du pointeur sur les données de la dialog dans les ressources
  352. // (qui a été renseigné par myFindRessource())
  353. static void myLoadDialog(unsigned char *ucData, DLGPROC bFunc, LPARAM lParam)
  354. {
  355.     DWORD    dwStyle;
  356.     DWORD    dwExtendedStyle; 
  357.     UWORD    wNbItem;
  358.     short    x, y, cx, cy; 
  359.     BOOL    bExtended;
  360.     char    szTitle[128], szFont[80];
  361.     UWORD    wTagMenu, wTagClasse;
  362.     OrdinalOrName leMenu;
  363.     OrdinalOrName laClasse;
  364.  
  365.     // Lire la signature
  366.     bExtended = (IntelWord(((UWORD*)  ucData) + 1) == 0xFFFF);
  367.  
  368.     if (bExtended)
  369.     {
  370.         ucData += 8;
  371.         dwExtendedStyle = IntelLong(((DWORD*) ucData)++);
  372.         dwStyle            = IntelLong(((DWORD*) ucData)++);
  373.     }
  374.     else
  375.     {
  376.         dwStyle            = IntelLong(((DWORD*) ucData)++);
  377.         dwExtendedStyle = IntelLong(((DWORD*) ucData)++);
  378.     }
  379.  
  380.     wNbItem            = IntelWord(((UWORD*)  ucData)++);
  381.     x                = IntelWord(((UWORD*)  ucData)++);
  382.     y                = IntelWord(((UWORD*)  ucData)++);
  383.     cx                = IntelWord(((UWORD*)  ucData)++);
  384.     cy                = IntelWord(((UWORD*)  ucData)++);
  385.  
  386.     // Le menu & la Classe
  387.     if ((wTagMenu = IntelWord(((UWORD*)ucData)++)) != 0x0000)     // Il y a un menu
  388.     {
  389.         if (wTagMenu == 0xFFFF) leMenu.wOrd = IntelWord(((UWORD*)ucData)++);
  390.         else ucData = myGetString(ucData, leMenu.szName);
  391.     }
  392.  
  393.     if ((wTagClasse = IntelWord(((UWORD*)ucData)++)) != 0x0000)     // Il y a une classe
  394.     {
  395.         if (wTagClasse == 0xFFFF) leMenu.wOrd = IntelWord(((UWORD*)ucData)++);
  396.         else ucData = myGetString(ucData, laClasse.szName);
  397.     }
  398.  
  399.     // Le nom
  400.     ucData = myGetString(ucData, szTitle);
  401.  
  402.     if ((dwStyle & DS_SETFONT) == DS_SETFONT)
  403.     {
  404.         ucData += 6;
  405.         ucData = myGetString(ucData, szFont);
  406.     }
  407.  
  408.     vTrace("DialogBox '%s' @(%d,%d), taille (%d,%d), %d contrôles",szTitle, x, y,cx,cy, wNbItem);
  409.  
  410.     // Créer la fenêtre
  411.     if (!(hWndDlg = CreateWindow(x, y, cx, cy, szTitle)))
  412.     {
  413.         vTrace("*** E0077 : ouverture dialog [%s] (%d, %d, %d, %d)", szTitle, x, y, cx, cy);
  414.         return;
  415.     }
  416.  
  417.     // Lecture des Items
  418.     while(wNbItem--)
  419.         ucData = myLoadDialogItem(hWndDlg, ucData);
  420.  
  421.     // Rafraîchir les gadgets
  422.     RefreshGadgets(hWndDlg -> FirstGadget, hWndDlg, NULL);
  423.  
  424.     // Appel de la DlgProc pour INITDIALOG, en lui passant lParam (comme ça ça marche pour DlgBox() et DlgBoxParam())
  425.     bDlgFunc = bFunc;
  426.     bDlgFunc(hWndDlg, WM_INITDIALOG, 0, lParam);
  427.  
  428.     // Ajout du sigbit de la dialog dans le masque global
  429.     lSigMask |= (1L << hWndDlg -> UserPort -> mp_SigBit);
  430. }
  431.  
  432. void vProcessDlgMessage(void)
  433. {
  434.     if (!hWndDlg) return;
  435.  
  436.     IntuiMessage *hMsg;
  437.  
  438.      // Traiter tous les messages dans la file de la fenêtre
  439.     while (hWndDlg && (hMsg = GT_GetIMsg(hWndDlg -> UserPort)))
  440.     {
  441.         APTR iAddress   = hMsg -> IAddress;
  442.         int  iClass      = hMsg -> Class,
  443.              iCode       = hMsg -> Code,
  444.              iGadId;
  445.  
  446.         GT_ReplyIMsg(hMsg);
  447.  
  448.         switch(iClass)
  449.         {
  450.             case IDCMP_GADGETUP:        // Click sur gadget dialog
  451.                 // Récupérer le pointeur sur le gadget
  452.                 iGadId = ((Gadget *) iAddress) -> GadgetID;
  453.  
  454.                 // Appeller la DlgProc en lui passant le code et le lParam
  455.                 bDlgFunc(hWndDlg, WM_COMMAND, (iCode << 16) | iGadId, (LPARAM) iAddress);
  456.                 break;
  457.  
  458.             case IDCMP_VANILLAKEY:
  459.                 switch(iCode)
  460.                 {
  461.                     case 27:        // Si Eskette, fin Dlg
  462.                         EndDialog(hWndDlg, -1);
  463.                         break;
  464.  
  465.                     default :
  466.                         vTrace("*** E0101 : code touche '%c' (%d) ignoré", iCode, iCode);
  467.                         break;
  468.                 }
  469.                 break;
  470.  
  471.             case IDCMP_MOUSEMOVE:
  472.                 bDlgFunc(hWndDlg, WM_HSCROLL, iCode, ((Gadget *) iAddress) -> GadgetID);
  473.                 break;
  474.  
  475.             default :
  476.                 vTrace("*** E0102 : IntuiMessage classe %d code %d ignoré", iClass, iCode);
  477.                 break;
  478.         }
  479.     }
  480. }
  481.  
  482. // Trouve une ressource dans le fichier de ressource en fonction de son nom et de son type
  483. static BOOL myFindResource(LPCTSTR lpTemplate, LPCTSTR lpType, ResEntry *res)
  484. {
  485.     unsigned char *ucBasePtr, *ucFin;
  486.     
  487.     ucBasePtr = amsResBasePtr;
  488.     ucFin = ucBasePtr + amsResSize;
  489.  
  490.     while(ucBasePtr < ucFin)
  491.     {
  492.         ucBasePtr = ReadResEntry(ucBasePtr, res);
  493.  
  494.         // Est-ce le bon type de ressource et la bonne ressource
  495.         if (CheckLPCT(lpType, res -> lpType) &&
  496.                 CheckLPCT(lpTemplate, res -> lpName))
  497.                     return TRUE;
  498.     }
  499.  
  500.     return FALSE;
  501. }
  502.  
  503. // Stubz des fonctions Windows pour les Dialog Boxes
  504. int DialogBox(HINSTANCE hInst, LPCTSTR sRes, HWND hWnd, DLGPROC bFunc)
  505. {
  506.     if (hWndDlg)
  507.     {
  508.         vTrace("*** E0078 : dialogue déjà ouvert");
  509.         return -1;
  510.     }
  511.  
  512.     ResEntry res;
  513.     vTrace("Chargement dialog %d", sRes);
  514.     if (myFindResource(sRes , (LPCTSTR) RT_DIALOG, &res))
  515.         myLoadDialog((unsigned char *) res.Data, bFunc, NULL); // Pas de lParam
  516.     else
  517.     {
  518.         vTrace("*** E0079 : dialog absent des ressources");
  519.         iDlgResult = -1;
  520.     }
  521.  
  522.     return iDlgResult;
  523. }
  524.  
  525. int DialogBoxParam(HINSTANCE hInst, LPCTSTR sRes, HWND hWnd, DLGPROC bFunc, LPARAM lParam)
  526. {
  527.     if (hWndDlg)
  528.     {
  529.         vTrace("*** E0080 : dialogue déjà ouvert");
  530.         return -1;
  531.     }
  532.  
  533.     ResEntry res;
  534.     vTrace("Chargement dialog %d (param. %ld)", sRes, lParam);
  535.     if (myFindResource(sRes , (LPCTSTR) RT_DIALOG, &res))
  536.         myLoadDialog((unsigned char *) res.Data, bFunc, lParam);
  537.     else
  538.     {
  539.         vTrace("*** E0081 : dialog absent des ressources");
  540.         iDlgResult = -1;
  541.     }
  542.  
  543.     return iDlgResult;
  544. }
  545.  
  546. BOOL EndDialog(HWND hWnd, int nResult)
  547. {
  548.     // Si la dialog n'est pas ouverte, ne rien faire
  549.     if (!hWnd) return FALSE;
  550.  
  551.     vTrace("Fin dialogue %s, code %d", hWnd -> Title, nResult);
  552.  
  553.     Forbid();
  554.         ModifyIDCMP(hWndDlg, 0L);
  555.         lSigMask &= ~(1L << hWndDlg -> UserPort -> mp_SigBit);  // Enlever le sigbit du mask du Wait()
  556.         Gadget *hGads = hWnd -> FirstGadget;                    // Récupérer un pointeur sur la gadlist de la dialog
  557.         hWnd -> FirstGadget = NULL;                             // Débrancher la gadlist de la dialog
  558.         CloseWindow(hWndDlg);                                   // Fermer la fenêtre
  559.         FreeGadgets(hGadgetList);                                     // Libérer les gadgets
  560.     Permit();
  561.  
  562.     hWndDlg = NULL;
  563.  
  564.     iDlgResult = nResult;
  565.  
  566.     return TRUE;
  567. }
  568.  
  569. int SendDlgItemMessage(HWND hWnd, int iGad, int iMsg, WPARAM wParam, LPARAM lParam)
  570. {
  571.     ULONG lTag = 0;
  572.     char *hStr;
  573.  
  574.     if (!hWnd)
  575.     {
  576.         vTrace("*** E0103 : hWnd nul");
  577.         return FALSE;
  578.     }
  579.  
  580.     Gadget *hGadget = hWnd -> FirstGadget;
  581.  
  582.     while (hGadget && hGadget -> GadgetID != iGad) hGadget = hGadget -> NextGadget;
  583.  
  584.     if (!hGadget)
  585.     {
  586.         vTrace("*** E0104 : gadget %d fenêtre %s non trouvé", iGad, hWnd -> Title);
  587.         return FALSE;
  588.     }
  589.  
  590.     switch(iMsg)
  591.     {
  592.         case WM_SETTEXT:
  593.             switch((int) (hGadget -> UserData))
  594.             {
  595.                 case TEXT_KIND:
  596.                     GT_SetGadgetAttrs(hGadget, hWnd, NULL, GTTX_Text, (ULONG) lParam, GTTX_CopyText, TRUE, TAG_DONE);
  597.                     break;
  598.                 default :
  599.                     GT_SetGadgetAttrs(hGadget, hWnd, NULL, GTST_String, (ULONG) lParam, TAG_DONE);
  600.                     break;
  601.             }
  602.             break;
  603.  
  604.         case WM_GETTEXT:
  605.             switch((int) (hGadget -> UserData))
  606.             {
  607.                 case TEXT_KIND:
  608.                     GT_GetGadgetAttrs(hGadget, hWnd, NULL, GTTX_Text, (ULONG) &hStr, TAG_DONE);
  609.                     break;
  610.                 default :
  611.                     GT_GetGadgetAttrs(hGadget, hWnd, NULL, GTST_String, (ULONG) &hStr, TAG_DONE);
  612.                     break;
  613.             }
  614.             strncpy((char *) lParam, hStr, wParam);
  615.             break;
  616.  
  617.         case BM_SETCHECK:
  618.             GT_SetGadgetAttrs(hGadget, hWnd, NULL, GTCB_Checked, (ULONG) wParam, TAG_DONE);
  619.             break;
  620.  
  621.         case BM_GETCHECK:
  622.             GT_GetGadgetAttrs(hGadget, hWnd, NULL, GTCB_Checked, (ULONG) &lTag, TAG_DONE);
  623.             break;
  624.  
  625.         case GA_Disabled:
  626.             GT_SetGadgetAttrs(hGadget, hWnd, NULL, GA_Disabled, (ULONG) wParam, TAG_DONE);
  627.             break;
  628.  
  629.         default:
  630.             vTrace("*** E0105 : classe de message %d non implémentée", iMsg);
  631.             break;
  632.     }
  633.  
  634.     return lTag;
  635. }
  636.  
  637. int GetDlgItem(HWND hWnd, int iGad)
  638. {
  639.     return iGad;
  640. }
  641.  
  642. int GetDlgCtrlID(int iGad)
  643. {
  644.     return iGad;
  645. }
  646.  
  647. void SetScrollInfo(int iGad, int iDummy, SCROLLINFO *hSi, BOOL bDummy)
  648. {
  649.     if (!hWndDlg)
  650.     {
  651.         vTrace("*** E0106 : hWnd nul");
  652.         return;
  653.     }
  654.  
  655.     Gadget *hGadget = hWndDlg -> FirstGadget;
  656.  
  657.     while (hGadget
  658.         && !(hGadget -> GadgetType != 259                         // ????? Apparemment les sliders créent 2 gadgets dont 100%de type 259 qui n'est pas le bon !
  659.           && hGadget -> GadgetID == iGad
  660.             )
  661.           )
  662.         hGadget = hGadget -> NextGadget;
  663.  
  664.     if (!hGadget)
  665.     {
  666.         vTrace("*** E0107 : Gadget %d fenêtre %s non trouvé", iGad, hWndDlg -> Title);
  667.         return;
  668.     }
  669.  
  670.     if ((hSi -> fMask) & SIF_RANGE)
  671.     {
  672.         GT_SetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Min, (ULONG) (hSi -> nMin), TAG_DONE);
  673.         GT_SetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Max, (ULONG) (hSi -> nMax), TAG_DONE);
  674.     }
  675.  
  676.     if ((hSi -> fMask) & SIF_POS)
  677.     {
  678.         GT_SetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Level, (ULONG) (hSi -> nPos), TAG_DONE);
  679.     }
  680. }
  681.  
  682. BOOL GetScrollInfo(int iGad, int iDummy, SCROLLINFO *hSi, BOOL bDummy)
  683. {
  684.     if (!hWndDlg)
  685.     {
  686.         vTrace("*** E0108 : hWnd nul");
  687.         return FALSE;
  688.     }
  689.  
  690.     Gadget *hGadget = hWndDlg -> FirstGadget;
  691.  
  692.     while (hGadget
  693.         && !(hGadget -> GadgetType != 259                         // ????? Apparemment les sliders créent 2 gadgets dont 100%de type 259 qui n'est pas le bon !
  694.           && hGadget -> GadgetID == iGad
  695.             )
  696.           )
  697.         hGadget = hGadget -> NextGadget;
  698.  
  699.     if (!hGadget)
  700.     {
  701.         vTrace("*** E0109 : Gadget %d fenêtre %s non trouvé", iGad, hWndDlg -> Title);
  702.         return FALSE;
  703.     }
  704.  
  705.     if ((hSi -> fMask) & SIF_RANGE)
  706.     {
  707.         GT_GetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Min, (ULONG) &(hSi -> nMin), TAG_DONE);
  708.         GT_GetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Max, (ULONG) &(hSi -> nMax), TAG_DONE);
  709.     }
  710.  
  711.     if ((hSi -> fMask) & SIF_POS)
  712.     {
  713.         GT_GetGadgetAttrs(hGadget, hWndDlg, NULL, GTSL_Level, (ULONG) &(hSi -> nPos), TAG_DONE);
  714.     }
  715.     return TRUE;
  716. }
  717.  
  718.